<!DOCTYPE html>
<html>
  <head>
    <style>
      #editor {
        position: relative;
        width: 500px;
        height: 400px;
        float: left;
      }
      
      div#bs-console{ border:1px solid black }
      div#dumparea{ border:1px solid black }
      div#dumparea div{ border-bottom: 1px solid black; margin:0 }
      span.dump_opecode{ color:orange; }
      span.dump_env{ color:goldenrod; }
      span.dump_stackframe{ color:cornflowerblue; }
      span.dump_closure{ color:limegreen; }
      span.dump_constant{ color:limegreen; }
      td.dump_dead{ color:lightgray; }
      td.dump_stknum{ color:gold; }
    </style>
  </head>
<body>
  <h1>
    <a href='../index.html'>BiwaScheme</a> tracer
    <small id="biwa_ver"></small>
  </h1>

  <div id="editor">;; write your code here
</div>
  <input type=button value="eval" onclick="eval_it()">

  <div id='bs-console'></div>

  <input type=button value="&lt;&lt;" onclick="dumper.dump_move_to(0)">
  <input type=button value="&lt;" onclick="dumper.dump_move(-1)">
  <input type=button value="&gt;" onclick="dumper.dump_move(1)">
  <input type=button value="&gt;&gt;" onclick="dumper.dump_move_to(-1)">
  <input type=button value="all" onclick="dumper.dump_toggle_fold()">

  <div id='dumparea'></div>

  <script type="text/javascript" src="ace/ace.js" charset="utf-8"></script>
  <script type="text/javascript" src="ace/theme-dawn.js" charset="utf-8"></script>
  <script type="text/javascript" src="ace/mode-clojure.js" charset="utf-8"></script>
  <script type="text/javascript" src="../src/development_initializer.js" charset="utf-8"></script>
  <script type="text/javascript">
  var eval_it, dumper;


  $(function(){
    $("#biwa_ver").append("("+BiwaScheme.VERSION+")");

    // init ace
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/dawn");
    var ClojureMode = require("ace/mode/clojure").Mode;
    editor.getSession().setMode(new ClojureMode());

    eval_it = function(){
      var show_error = function(e){
        Console.puts("Error: "+e.message);
        throw e;
      };
      dumper.reset();
      $("#bs-console").html("");
      var src = editor.getSession().getValue();
      var intp = new BiwaScheme.Interpreter(show_error);
      try{
        var ret = intp.evaluate(src);
        Console.puts(";=> " + BiwaScheme.to_write(ret));
      }
      catch(e){
        console.error(e);
      }
      dumper.dump_move(1);
    }

    dumper = new BiwaScheme.Dumper();
    BiwaScheme.Interpreter.dumper = dumper;

    eval_it();
  });

  </script>
</body>
</html>
<!-- vim:set ft=javascript: -->
